import http from '../../core/request'
import { UserOrder } from './userOrder.type'
// 用户订单
export const userOrderList = (data: UserOrder.Req.UserOrderList) => {
  return http.get<UserOrder.Res.UserOrderList>('/customer-order', data,{
    loading: true
  })
}

// 用户订单详情
export const userOrderDetail = (id: string) => {
  return http.get<UserOrder.Res.UserOrderDetail>(`/customer-order/${id}`, {}, {
    loading: true
  })
}


// 下一步
export const userNextStep = (id: string) => {
  return http.patch(`/customer-order/${id}/next`,{},{
    loading: true
  })
}
// 上一步
export const userLastStep = (id: string) => {
  return http.patch(`/customer-order/${id}/last`,{},{
    loading: true
  })
}
// 取消订单
export const userCancelOrder = (id: string) => {
  return http.put(`/customer-order/${id}/cancel`,{},{
    loading: true
  })
}
// 确认价格
export const userConfirmPrice = (id: string,data: UserOrder.Req.UserConfirmPrice) => {
  return http.put(`/customer-order/${id}/confirm-price`,data,{
    loading: true
  })
}
// 修改物流
export const updateLogistics = (id: string, data: UserOrder.Req.UserUpdateLogistics) => {
  return http.put(`/customer-order/${id}/logistics`, data,{
    loading: true
  })
}
// 修改上门信息
export const updateUpstairsInfo = (id: string, data: UserOrder.Req.UserUpdateUpstairsInfo) => {
  return http.put(`/customer-order/${id}/UserOrder`, data,{
    loading: true
  })
}
// 转交订单
export const transferOrder = (id: string,data: {
  toUserId: string
}) => {
  return http.put(`/customer-order/${id}/deliver`,data,{
    loading: true
  })
}
// 查询关联订单
export const queryUserOrder = (code: string) => {
  return http.get<UserOrder.Res.UserOrderDetail>(`/customer-order/code/${code}`,{},{
    loading: true
  })
}

// 加盟商订单列表
export const franchiseOrderList = (data: UserOrder.Req.FranchiseList) => {
  return http.get<UserOrder.Res.UserOrderList>('/order', data,{
    loading: true
  })
}
// 加盟商订单详情
export const franchiseOrderDetail = (id: string) => {
  return http.get<UserOrder.Res.UserOrderDetail>(`/order/${id}`, {}, {
    loading: true
  })
}

// 加盟商下单
export const franchiseOrderCreate = (data: UserOrder.Req.FranchiseOrderCreate) => {
  return http.post('/order/place', data,{
    loading: true
  })
}

// 加盟商取消订单加盟商取消订单
export const franchiseCancelOrder = (id: string) => {
  return http.put(`/order/${id}/cancel`,{},{
    loading: true
  })
}
// 修改加盟物流订单
export const franchiseUpdateLogistics = (id: string, data: UserOrder.Req.UserUpdateLogistics) => {
  return http.put(`/order/${id}/logistics`, data,{
    loading: true
  })
}
// 修改加盟商收款信息
export const franchiseUpdatePayment = (id: string, data:{
  receiptType: string,
}) => {
  return http.put(`/order/${id}/payment`, data,{
    loading: true
  })
}
// 加盟商确认订单
export const franchiseConfirmOrder = (id: string,data:{
  subStatus: string
}) => {
  return http.put(`/order/${id}/user-confirm`,data,{
    loading: true
  })
}

// 加盟商下一步
export const franchiseNextStep = (id: string) => {
  return http.put(`/order/${id}/next`,{},{
    loading: true
  })
}

// 加盟商上一步
export const franchiseLastStep = (id: string) => {
  return http.put(`/order/${id}/last`,{},{
    loading: true
  })
}

export default {
  userOrderList,
  userOrderDetail,
  userNextStep,
  userLastStep,
  userCancelOrder,
  userConfirmPrice,
  queryUserOrder,
  transferOrder,
  updateLogistics,
  updateUpstairsInfo,
  franchiseOrderList,
  franchiseOrderCreate,
  franchiseCancelOrder,
  franchiseNextStep,
  franchiseLastStep,
  franchiseOrderDetail,
  franchiseUpdateLogistics,
  franchiseConfirmOrder,
  franchiseUpdatePayment
}
